﻿using System;
using System.Data;
using BO.Infrastructure.StaticData;
using BO.Infrastructure.Utils;

namespace GUI.Controls.Sport
{
    public partial class ListNews : System.Web.UI.UserControl
    {
        private const string LiFormat = @"<li>{3}<div class=""text fl""><h2><a title=""{0}"" href=""{2}"">{1}{6}</a></h2><p class=""time fl"">{4}</p><p>{5}</p></div></li>";
        private const int ImageWidth = 160;
        private const int ImageHeight = 120;

        protected void Page_Load(object sender, EventArgs e)
        {

        }

        public bool DataBind(DataTable dt)
        {
            
                if (dt != null && dt.Rows.Count > 0)
                {
                    var sb = new System.Text.StringBuilder();
                    foreach(DataRow r in dt.Rows)
                    {
                        var avatar = PresentationUtils.Photo.BuildNewsAvatar(r, ImageWidth, ImageHeight, lazyLoad: true);

                        sb.Append(string.Format(LiFormat,
                            r[SqlConstants.NewsPublish.EncodedTitle],
                            r[SqlConstants.NewsPublish.Title],
                            r[SqlConstants.NewsPublish.Url],
                            avatar,
                            PresentationUtils.Object2DateTime(r[SqlConstants.NewsPublish.DistributionDate].ToString()).ToString("dd/MM/yyyy HH:mm"),
                            r[SqlConstants.NewsPublish.InitSapo],
                            r[SqlConstants.NewsPublish.NewsTypeIcon]
                            ));
                    }
                    ltrList.Text = sb.ToString();
                    return true;
                }
         
            return false;
        }
    }
}